function init() {
    let btn_num1 = "";
    let sign;
    let num = document.querySelector("#num");
    num.value = 0;
    num.disabled = "disabled";
    let btn = document.getElementsByTagName("input");
    for (let i = 0; i < btn.length; i++) {
        btn[i].onclick = function () {
            if (isNumber(this.value)) {
                if (isNull(num.value)) {
                    num.value = this.value
                } else {
                    num.value = num.value + this.value
                }
            } else {
                let btn_num = this.value;
                switch (btn_num) {
                    case "+":
                        btn_num1 = Number(num.value);
                        num.value = 0;
                        sign = "+";
                        break;
                    case "-":
                        btn_num1 = Number(num.value);
                        num.value = 0;
                        sign = "-";
                        break;
                    case "*":
                        btn_num1 = Number(num.value);
                        num.value = 0;
                        sign = "*";
                        break;
                    case "/":
                        btn_num1 = Number(num.value);
                        num.value = 0;
                        sign = "/";
                        break;
                    case ".":
                        num.value = decimal(num.value);
                        break;
                    case "←":
                        num.value = back(num.value);
                        break;
                    case "C":
                        num.value = 0;
                        break
                    case "+/-":
                        num.value = numSign(num.value);
                        break
                    case "=":
                        switch (sign) {
                            case "+":
                                num.value = btn_num1 + Number(num.value)
                                break;
                            case "-":
                                num.value = btn_num1 - Number(num.value)
                                break;
                            case "*":
                                num.value = btn_num1 * Number(num.value)
                                break;
                            case "/":
                                if (num.value != 0) {
                                    num.value = btn_num1 / Number(num.value)
                                } else {
                                    alert("除数不能为0")
                                }
                                break;
                        }
                        break;
                }
            }
        }
    }
}

function isNumber(n) {
    return !isNaN(n)
}

//验证文本框
function isNull(n) {
    if (n * 1 == 0 || n.length == 0) {
        return true
    } else {
        return false
    }
}


function decimal(n) {
    if (n.indexOf(".") === -1) {
        n = n + "."
    }
    return n
}

//退位
function back(n) {
    n = n.substr(0, n.length - 1);
    if (isNull(n)) {
        n = 0
    }
    return n
}

//正负号
function numSign(n) {
    n = Number(n) * -1
    return n
}

function jump_to_page() {
    document.getElementById("m").onclick = function () {
        window.location.href = "http://www.baidu.com"
    }
}